package com.ruoyi.achievements.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.achievements.domain.JwTeachAchievements;
import com.ruoyi.achievements.service.IJwTeachAchievementsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教学成果奖Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/achievements/achievements")
public class JwTeachAchievementsController extends BaseController
{
    @Autowired
    private IJwTeachAchievementsService jwTeachAchievementsService;

    /**
     * 查询教学成果奖列表
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwTeachAchievements jwTeachAchievements)
    {
        startPage();
        List<JwTeachAchievements> list = jwTeachAchievementsService.selectJwTeachAchievementsList(jwTeachAchievements);
        return getDataTable(list);
    }

    /**
     * 导出教学成果奖列表
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:export')")
    @Log(title = "教学成果奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwTeachAchievements jwTeachAchievements)
    {
        List<JwTeachAchievements> list = jwTeachAchievementsService.selectJwTeachAchievementsList(jwTeachAchievements);
        ExcelUtil<JwTeachAchievements> util = new ExcelUtil<JwTeachAchievements>(JwTeachAchievements.class);
        util.exportExcel(response, list, "教学成果奖数据");
    }

    /**
     * 获取教学成果奖详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:query')")
    @GetMapping(value = "/{teachId}")
    public AjaxResult getInfo(@PathVariable("teachId") Long teachId)
    {
        return success(jwTeachAchievementsService.selectJwTeachAchievementsByTeachId(teachId));
    }

    /**
     * 新增教学成果奖
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:add')")
    @Log(title = "教学成果奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwTeachAchievements jwTeachAchievements)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwTeachAchievements.setDeptId(104L);
        jwTeachAchievements.setUserId(user.getUserId());
        return toAjax(jwTeachAchievementsService.insertJwTeachAchievements(jwTeachAchievements));
    }

    /**
     * 修改教学成果奖
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:edit')")
    @Log(title = "教学成果奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwTeachAchievements jwTeachAchievements)
    {
        return toAjax(jwTeachAchievementsService.updateJwTeachAchievements(jwTeachAchievements));
    }

    /**
     * 删除教学成果奖
     */
    @PreAuthorize("@ss.hasPermi('achievements:achievements:remove')")
    @Log(title = "教学成果奖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teachIds}")
    public AjaxResult remove(@PathVariable Long[] teachIds)
    {
        return toAjax(jwTeachAchievementsService.deleteJwTeachAchievementsByTeachIds(teachIds));
    }
}
